﻿#region References

using System;
using App_Code.Objects;
using SignalR;
using SignalR.Hosting.AspNet;
using SignalR.Infrastructure;

#endregion
namespace App_Code.Logic
{
    /// <summary>
    /// Summary description for SignalRLogic
    /// </summary>
    public class SignalRLogic
    {
        #region Properties
        private static dynamic Clients
        {
            get
            {
                return GetVisualCronClients();
            }
        }

        #endregion

        #region Public methods
        public static void SendServerConnected(string clientId, object diff)
        {
            Clients[clientId].serverConnected(diff);
        }

        public static void SendServerDisconnected(string clientId, string serverId, string message)
        {
            var clients = GetVisualCronClients();
            clients[clientId].serverDisconnected(serverId, message);
        }

        public static void SendJobsUpdated(string clientId, string serverId, object jobs)
        {
            var clients = GetVisualCronClients();
            clients[clientId].jobsUpdated(serverId, jobs);

        }

        public static void SendJobAdded(string clientId, string serverId, object job)
        {
            var clients = GetVisualCronClients();
            clients[clientId].jobAdded(serverId, job);
        }

        public static void SendJobRemoved(string clientId, string serverId, object job)
        {
            var clients = GetVisualCronClients();
            clients[clientId].jobRemoved(serverId, job);
        }

        public static void SendJobUpdated(string clientId, string serverId, JobDTO job)
        {
            Clients[clientId].jobUpdated(serverId, job);
        }

        public static void SendConnectionStateChanged(string clientId, object listConnections)
        {
            Clients[clientId].connectionStateChanged(listConnections);
        }

        public static void SendTaskAdded(string clientId, string serverId, string jobId, TaskDTO task)
        {
            Clients[clientId].taskAdded(serverId, jobId, task);
        }

        public static void SendTaskRemoved(string clientId, string serverId, string jobId, TaskDTO task)
        {
            Clients[clientId].taskRemoved(serverId, jobId, task);
        }

        public static void SendTaskUpdated(string clientId, string serverId, string jobId, TaskDTO task)
        {
            Clients[clientId].taskUpdated(serverId, jobId, task);
        }

        public static void SendConnectionError(string clientId, string connectionId, bool isLoginError, string message)
        {
            Clients[clientId].connectionError(connectionId, isLoginError, message);
        }
        #endregion


        #region Private methods
        private static dynamic GetVisualCronClients()
        {
            return AspNetHost.DependencyResolver.Resolve<IConnectionManager>().GetClients<VisualCronHub>();
        }

	#endregion

    }
}